<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="__PUBLIC__/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="__PUBLIC__/css/my.css">
    <title>用户登录</title>
</head>
<body>
<body class="adminlogin">

<div class="conatiner mt50">
    <div class="clearfix mt50"></div>
    <h1 class="text-center mt50">用  户 注 册</h1>
    <hr>
    <form onsubmit="return false;" class="form-horizontal col-md-4 col-md-offset-4">
        <div class="form-group">
            <div class="col-md-12">
                <div class="form-group">
                    <label for="username" class="col-sm-3 control-label">用户名　</label>
                    <div class="col-sm-9">
                        <input id="username" type="text" class="form-control" name="username" placeholder="用户名">
                        <span style="color:red;"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="nickname" class="col-sm-3 control-label">昵　　称</label>
                    <div class="col-sm-9">
                        <input id="nickname" type="text" class="form-control" name="nickname" placeholder="昵称">
                        <span style="color:red;"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputEmail" class="col-sm-3 control-label">昵　　称</label>
                    <div class="col-sm-9">
                        <input id="inputEmail" type="email" class="form-control" name="email" placeholder="邮箱">
                        <span style="color:red;"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="password" class="col-sm-3 control-label">密　　码</label>
                    <div class="col-sm-9">
                        <input id="password" type="password" name="passwd" class="form-control" id="password" placeholder="请输入密码">
                        <span style="color:red;"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="repassword" class="col-sm-3 control-label">确认密码</label>
                    <div class="col-sm-9">
                        <input id="repassword" type="password" name="repasswd" class="form-control" id="repassword" placeholder="请再次输入密码">
                        <span style="color:red;"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-12">
                        <div class="pull-left">
                            <input type="text" name="vcode" class="form-control" placeholder="验证码">
                            <span style="color:red;"></span>
                        </div>
                        <div class="pull-right">
                            <img src="{:U('User/yzm')}" title="点 我 刷 新" style="cursor:pointer" onclick="this.src=this.src+'?i='+Math.random()" class="pull-right verify">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-12">
                        <button  class="btn btn-primary btn-lg btn-block reg">注册</button>
                       <!--  <a href="" class="pull-right">返回首页</a> -->
                    </div>
                </div>
    </form>
</div><!-- END container -->
<!-- 此处引入jQuery -->
<script src="__PUBLIC__/js/jquery.min.js"></script>
<!-- bootstrap.min.js必须放在JQ后面 -->
<script src="__PUBLIC__/js/bootstrap.min.js"></script>
<script>
    $('.reg').click(function(){
        $.ajax({
            type: "POST",
            url: "{:U('User/startReg')}",
            data: $('form').serialize(),
            success: function(data){
                if(data['status'] == 0)
                {
                    alert('注册成功!');
                    window.location.href="{:U('User/login')}";
                }else if(data['status'] == 1)
                {
                    for(var i in data['message'])
                    {
                        $("input[name='"+i+"']+span").text(data['message'][i]);
                    }
                }
            }
        });
    });
    $('input').focusout(function(){
        var value = $(this).val();//取输入框的值
        var who = $(this).attr('name');//取输入框name的值
        var ts = {'username':'用户名','nickname':'昵称','passwd':'密码','repasswd':'确认密码'};
        var data = $(this).serialize();//拼接AJAX发送的数据
        if(who == 'vcode')
        {
            if(value == '')
            {
                $("input[name='vcode']+span").text('验证码不能为空!');
            }else
            {
                $("input[name='vcode']+span").text('');
            }
            return false;;
        }
        if(who == 'repasswd')
        {
            data+='&'+$("input[name='passwd']").serialize();
        }
        $.ajax({
            type:"POST",
            url:"{:U('User/verifyReg')}",
            data:data,
            success:function(data){
                if(data.status == 0)
                {
                    $("input[name='"+who+"']+span").text('');
                }else if(data.status == 1)
                {
                    $("input[name='"+who+"']+span").text(data['message'][who]);
                }
            }
        });
    });
</script>
</body>
</html>